<template>
  <div>
    <el-card>
      {{$route.query.id}}
      <el-button type="success" @click="but=true" circle>本机构</el-button>
      <el-button type="info" @click="but=false" circle>其他机构</el-button>
      <el-form ref="form" :model="formData" label-width="80px">
        <el-row v-if="but">
          <el-form-item label="科室" prop="divName">
            <el-select v-model="formData.sectionId" clearable style="margin-left: 20px;" placeholder="请选择">
              <el-option
                v-for="item in sectionname"
                :key="item.id"
                :label="item.divName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row v-else>
          <el-form-item label="机构名称" prop="orgName">
            <el-select v-model="formData.orgId" clearable style="margin-left: 20px;" placeholder="请选择">
              <el-option
                v-for="item in forname"
                :key="item.id"
                :label="item.orgName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="科室" prop="divName">
            <el-select v-model="formData.divName" clearable style="margin-left: 20px;" placeholder="请选择">
              <el-option
                v-for="item in sectionname"
                :key="item.id"
                :label="item.divName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-button type="success" @click="submit">提交</el-button>
          <el-button type="info" @click="$router.go(-1)">返回</el-button>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  import {post} from "@/utils/api";
  export default {
    data() {
      return {
        formData:{},
        but:true,
        forname:[],
        sectionname:[],
      }
    },
    async created() {
      let res = await post("org/getallorg")
      this.forname = res
      this.getallsection()
      this.getpersonid()
    },
    methods: {
      async getallsection() {
        let res = await post("section/getallsection")
        this.sectionname = res
        console.log(res)
      },
      async getpersonid() {
        let res = await post("/person/getbypersonid",{id:this.$route.query.id})
        console.log(res)
        this.formData= res
      },
      async submit(){
        await post("person/getbypersonidupdate",{...this.formData})
        console.log(this.formData)
      },

    },
  }
</script>
<style></style>
